<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card>
            <el-row>
                <el-col :span="6">
                    <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getOrderList">
                        <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <el-table :data="orderList" border stripe>
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column label="订单编号" prop="order_number"></el-table-column>
                <el-table-column label="订单价格" prop="order_price" width="80px"></el-table-column>
                <el-table-column label="是否付款" width="80px">
                  <template slot-scope="scope">
                    <el-tag v-if="scope.row.order_pay !== '0'" type="parmiry">已付款</el-tag>
                    <el-tag v-else type="warning">未付款</el-tag>
                  </template>
                </el-table-column>
                <el-table-column label="是否发货" prop="is_send" width="80px"></el-table-column>
                <el-table-column label="下单时间" width="180px">
                  <template slot-scope="scope">
                    {{scope.row.create_time | dataFormat}}
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="140px">
                    <el-button type="primary" icon="el-icon-edit" size="mini" @click="showBox"></el-button>
                    <el-button type="success" icon="el-icon-location" @click="showLocalcation" size="mini"></el-button>
                </el-table-column>
            </el-table>
            <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[10, 20, 30, 50]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
        </el-card>
        <el-dialog
  title="修改地址"
  :visible.sync="editDialogVisible"
  width="50%"
  >
  <el-form :model="editList" ref="editFormRef" :rules="editFormRule" label-width="90px">
    <el-form-item label="省市区/县" prop="city">
      <el-cascader
        v-model="editList.city"
        :options="cityData"
        :props="cascaderProps"
        @change="handleChange"
        @close="handleClose">
      </el-cascader>
    </el-form-item>
    <el-form-item label="详细地址" prop="localcation">
      <el-input v-model="editList.localcation"></el-input>
    </el-form-item>
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
</el-dialog>
<el-dialog
  title="查看物流"
  :visible.sync="localcationDialogVisible"
  width="50%"
  @close="closeLocalDialog"
  >
  <el-timeline>
    <el-timeline-item
      v-for="(activity, index) in localcationInfo"
      :key="index"
      :timestamp="activity.time">
      {{activity.context}}
    </el-timeline-item>
  </el-timeline>
  <span slot="footer" class="dialog-footer">
    <el-button @click="localcationDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="localcationDialogVisible = false">确 定</el-button>
  </span>
</el-dialog>
    </div>
</template>
<script>
import cityData from './citydata'
export default {
  name: 'order',
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      total: 0,
      editDialogVisible: false,
      editList: {
        city: [],
        localcation: ''
      },
      editFormRule: {
        city: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' }
        ],
        localcation: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      },
      cityData,
      cascaderProps: {
        expandTrigger: 'hover',
        value: 'value',
        label: 'label',
        children: 'children'
      },
      localcationDialogVisible: false,
      localcationInfo: [],
      reverse: true
    }
  },
  methods: {
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) return
      //   console.log(res)
      this.orderList = res.data.goods
      this.total = res.data.total
      console.log(this.orderList)
      // console.log(this.cityData)
    },
    handleSizeChange (newsize) {
      this.queryInfo.pagesize = newsize
      this.getOrderList()
    },
    handleCurrentChange (newpage) {
      this.queryInfo.pagenum = newpage
      this.getOrderList()
    },
    showBox () {
      this.editDialogVisible = true
    },
    handleChange () {
      console.log(this.editList.city)
    },
    handleClose () {
      this.$refs.editFormRef.resetFields()
      this.editDialogVisible = false
    },
    async showLocalcation () {
      this.localcationDialogVisible = true
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      if (res.meta.status !== 200) return
      this.localcationInfo = res.data
    },
    closeLocalDialog () {
      this.localcationInfo = []
    }
  },
  created () {
    this.getOrderList()
  }
}
</script>
<style lang="less" scoped>
@import url('../../plugins/timeline/timeline.css');
@import url('../../plugins/timeline-item/timeline-item(1).css');
</style>
